
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/13/2013 16:10:01
-- Generated from EDMX file: D:\DEV\Aptech\Sem3\Zax\m\db\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ACCP1109A1];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Event_Detail_Event]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Occasion_Detail] DROP CONSTRAINT [FK_Event_Detail_Event];
GO
IF OBJECT_ID(N'[dbo].[FK_Event_Detail_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Occasion_Detail] DROP CONSTRAINT [FK_Event_Detail_Product];
GO
IF OBJECT_ID(N'[dbo].[FK_Messenger_Occasion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Messenger] DROP CONSTRAINT [FK_Messenger_Occasion];
GO
IF OBJECT_ID(N'[dbo].[FK_Order_Detail_Order]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order_Detail] DROP CONSTRAINT [FK_Order_Detail_Order];
GO
IF OBJECT_ID(N'[dbo].[FK_Order_Detail_Product]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order_Detail] DROP CONSTRAINT [FK_Order_Detail_Product];
GO
IF OBJECT_ID(N'[dbo].[FK_Order_UserProfile]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Order] DROP CONSTRAINT [FK_Order_UserProfile];
GO
IF OBJECT_ID(N'[dbo].[fk_RoleId]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[webpages_UsersInRoles] DROP CONSTRAINT [fk_RoleId];
GO
IF OBJECT_ID(N'[dbo].[fk_UserId]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[webpages_UsersInRoles] DROP CONSTRAINT [fk_UserId];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Messenger]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Messenger];
GO
IF OBJECT_ID(N'[dbo].[Occasion]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Occasion];
GO
IF OBJECT_ID(N'[dbo].[Occasion_Detail]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Occasion_Detail];
GO
IF OBJECT_ID(N'[dbo].[Order]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Order];
GO
IF OBJECT_ID(N'[dbo].[Order_Detail]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Order_Detail];
GO
IF OBJECT_ID(N'[dbo].[Product]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Product];
GO
IF OBJECT_ID(N'[dbo].[sysdiagrams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysdiagrams];
GO
IF OBJECT_ID(N'[dbo].[UserProfile]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserProfile];
GO
IF OBJECT_ID(N'[dbo].[webpages_Membership]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_Membership];
GO
IF OBJECT_ID(N'[dbo].[webpages_OAuthMembership]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_OAuthMembership];
GO
IF OBJECT_ID(N'[dbo].[webpages_Roles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_Roles];
GO
IF OBJECT_ID(N'[dbo].[webpages_UsersInRoles]', 'U') IS NOT NULL
    DROP TABLE [dbo].[webpages_UsersInRoles];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Occasions'
CREATE TABLE [dbo].[Occasions] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Banner] nvarchar(max)  NULL
);
GO

-- Creating table 'Occasion_Details'
CREATE TABLE [dbo].[Occasion_Details] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Product_ID] int  NOT NULL,
    [Occasion_ID] int  NOT NULL
);
GO

-- Creating table 'Orders'
CREATE TABLE [dbo].[Orders] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Create_Date] datetime  NULL,
    [Pay_Date] datetime  NULL,
    [Order_Date] datetime  NULL,
    [Ship_Date] datetime  NULL,
    [MapLocation] varchar(20)  NULL,
    [Address] nvarchar(100)  NULL,
    [Note] nvarchar(200)  NULL,
    [Customer_ID] int  NOT NULL
);
GO

-- Creating table 'Order_Details'
CREATE TABLE [dbo].[Order_Details] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Order_ID] int  NOT NULL,
    [Product_ID] int  NOT NULL,
    [Quantity] int  NOT NULL,
    [Unit_Price] int  NOT NULL
);
GO

-- Creating table 'Products'
CREATE TABLE [dbo].[Products] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(20)  NOT NULL,
    [Price] int  NOT NULL,
    [Detail] nvarchar(max)  NULL
);
GO

-- Creating table 'sysdiagrams'
CREATE TABLE [dbo].[sysdiagrams] (
    [name] nvarchar(128)  NOT NULL,
    [principal_id] int  NOT NULL,
    [diagram_id] int IDENTITY(1,1) NOT NULL,
    [version] int  NULL,
    [definition] varbinary(max)  NULL
);
GO

-- Creating table 'UserProfiles'
CREATE TABLE [dbo].[UserProfiles] (
    [UserId] int IDENTITY(1,1) NOT NULL,
    [UserName] nvarchar(30)  NOT NULL,
    [First_Name] nvarchar(50)  NULL,
    [Last_Name] nvarchar(50)  NULL,
    [Phone] nchar(20)  NULL
);
GO

-- Creating table 'webpages_Membership'
CREATE TABLE [dbo].[webpages_Membership] (
    [UserId] int  NOT NULL,
    [CreateDate] datetime  NULL,
    [ConfirmationToken] nvarchar(128)  NULL,
    [IsConfirmed] bit  NULL,
    [LastPasswordFailureDate] datetime  NULL,
    [PasswordFailuresSinceLastSuccess] int  NOT NULL,
    [Password] nvarchar(128)  NOT NULL,
    [PasswordChangedDate] datetime  NULL,
    [PasswordSalt] nvarchar(128)  NOT NULL,
    [PasswordVerificationToken] nvarchar(128)  NULL,
    [PasswordVerificationTokenExpirationDate] datetime  NULL
);
GO

-- Creating table 'webpages_OAuthMembership'
CREATE TABLE [dbo].[webpages_OAuthMembership] (
    [Provider] nvarchar(30)  NOT NULL,
    [ProviderUserId] nvarchar(100)  NOT NULL,
    [UserId] int  NOT NULL
);
GO

-- Creating table 'webpages_Roles'
CREATE TABLE [dbo].[webpages_Roles] (
    [RoleId] int IDENTITY(1,1) NOT NULL,
    [RoleName] nvarchar(256)  NOT NULL
);
GO

-- Creating table 'Messengers'
CREATE TABLE [dbo].[Messengers] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Text] nvarchar(max)  NULL,
    [Occasion_ID] int  NOT NULL
);
GO

-- Creating table 'webpages_UsersInRoles'
CREATE TABLE [dbo].[webpages_UsersInRoles] (
    [webpages_Roles_RoleId] int  NOT NULL,
    [UserProfiles_UserId] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'Occasions'
ALTER TABLE [dbo].[Occasions]
ADD CONSTRAINT [PK_Occasions]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Occasion_Details'
ALTER TABLE [dbo].[Occasion_Details]
ADD CONSTRAINT [PK_Occasion_Details]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [PK_Orders]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Order_Details'
ALTER TABLE [dbo].[Order_Details]
ADD CONSTRAINT [PK_Order_Details]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [PK_Products]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [diagram_id] in table 'sysdiagrams'
ALTER TABLE [dbo].[sysdiagrams]
ADD CONSTRAINT [PK_sysdiagrams]
    PRIMARY KEY CLUSTERED ([diagram_id] ASC);
GO

-- Creating primary key on [UserId] in table 'UserProfiles'
ALTER TABLE [dbo].[UserProfiles]
ADD CONSTRAINT [PK_UserProfiles]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [UserId] in table 'webpages_Membership'
ALTER TABLE [dbo].[webpages_Membership]
ADD CONSTRAINT [PK_webpages_Membership]
    PRIMARY KEY CLUSTERED ([UserId] ASC);
GO

-- Creating primary key on [Provider], [ProviderUserId] in table 'webpages_OAuthMembership'
ALTER TABLE [dbo].[webpages_OAuthMembership]
ADD CONSTRAINT [PK_webpages_OAuthMembership]
    PRIMARY KEY CLUSTERED ([Provider], [ProviderUserId] ASC);
GO

-- Creating primary key on [RoleId] in table 'webpages_Roles'
ALTER TABLE [dbo].[webpages_Roles]
ADD CONSTRAINT [PK_webpages_Roles]
    PRIMARY KEY CLUSTERED ([RoleId] ASC);
GO

-- Creating primary key on [ID] in table 'Messengers'
ALTER TABLE [dbo].[Messengers]
ADD CONSTRAINT [PK_Messengers]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [webpages_Roles_RoleId], [UserProfiles_UserId] in table 'webpages_UsersInRoles'
ALTER TABLE [dbo].[webpages_UsersInRoles]
ADD CONSTRAINT [PK_webpages_UsersInRoles]
    PRIMARY KEY NONCLUSTERED ([webpages_Roles_RoleId], [UserProfiles_UserId] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Occasion_ID] in table 'Occasion_Details'
ALTER TABLE [dbo].[Occasion_Details]
ADD CONSTRAINT [FK_Occasion_Detail_Event]
    FOREIGN KEY ([Occasion_ID])
    REFERENCES [dbo].[Occasions]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Occasion_Detail_Event'
CREATE INDEX [IX_FK_Occasion_Detail_Event]
ON [dbo].[Occasion_Details]
    ([Occasion_ID]);
GO

-- Creating foreign key on [Product_ID] in table 'Occasion_Details'
ALTER TABLE [dbo].[Occasion_Details]
ADD CONSTRAINT [FK_Occasion_Detail_Product]
    FOREIGN KEY ([Product_ID])
    REFERENCES [dbo].[Products]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Occasion_Detail_Product'
CREATE INDEX [IX_FK_Occasion_Detail_Product]
ON [dbo].[Occasion_Details]
    ([Product_ID]);
GO

-- Creating foreign key on [Order_ID] in table 'Order_Details'
ALTER TABLE [dbo].[Order_Details]
ADD CONSTRAINT [FK_Order_Detail_Order]
    FOREIGN KEY ([Order_ID])
    REFERENCES [dbo].[Orders]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Order_Detail_Order'
CREATE INDEX [IX_FK_Order_Detail_Order]
ON [dbo].[Order_Details]
    ([Order_ID]);
GO

-- Creating foreign key on [Customer_ID] in table 'Orders'
ALTER TABLE [dbo].[Orders]
ADD CONSTRAINT [FK_Order_UserProfile]
    FOREIGN KEY ([Customer_ID])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Order_UserProfile'
CREATE INDEX [IX_FK_Order_UserProfile]
ON [dbo].[Orders]
    ([Customer_ID]);
GO

-- Creating foreign key on [Product_ID] in table 'Order_Details'
ALTER TABLE [dbo].[Order_Details]
ADD CONSTRAINT [FK_Order_Detail_Product]
    FOREIGN KEY ([Product_ID])
    REFERENCES [dbo].[Products]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Order_Detail_Product'
CREATE INDEX [IX_FK_Order_Detail_Product]
ON [dbo].[Order_Details]
    ([Product_ID]);
GO

-- Creating foreign key on [webpages_Roles_RoleId] in table 'webpages_UsersInRoles'
ALTER TABLE [dbo].[webpages_UsersInRoles]
ADD CONSTRAINT [FK_webpages_UsersInRoles_webpages_Roles]
    FOREIGN KEY ([webpages_Roles_RoleId])
    REFERENCES [dbo].[webpages_Roles]
        ([RoleId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UserProfiles_UserId] in table 'webpages_UsersInRoles'
ALTER TABLE [dbo].[webpages_UsersInRoles]
ADD CONSTRAINT [FK_webpages_UsersInRoles_UserProfile]
    FOREIGN KEY ([UserProfiles_UserId])
    REFERENCES [dbo].[UserProfiles]
        ([UserId])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_webpages_UsersInRoles_UserProfile'
CREATE INDEX [IX_FK_webpages_UsersInRoles_UserProfile]
ON [dbo].[webpages_UsersInRoles]
    ([UserProfiles_UserId]);
GO

-- Creating foreign key on [Occasion_ID] in table 'Messengers'
ALTER TABLE [dbo].[Messengers]
ADD CONSTRAINT [FK_Messenger_Occasion]
    FOREIGN KEY ([Occasion_ID])
    REFERENCES [dbo].[Occasions]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Messenger_Occasion'
CREATE INDEX [IX_FK_Messenger_Occasion]
ON [dbo].[Messengers]
    ([Occasion_ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------